/**
 * Auto gen via dbpojo-gen.
 */
package com.us.usws.service.ro.impl;

import java.util.List;

import com.us.usws.cache.UserCache;
import com.us.usws.dao.VideoCommentDAO;
import com.us.usws.dao.VideoDAO;
import com.us.usws.model.domain.system.User;
import com.us.usws.model.domain.video.Video;
import com.us.usws.model.domain.video.VideoComment;
import com.us.usws.service.ro.VideoCommentROService;
import com.us.usws.support.ext.CacheManager;
import com.us.usws.support.uitls.DataPageUtil;

/**
 * Service RO impl class
 * @author robot
 */
public class VideoCommentROServiceImpl implements VideoCommentROService {

	/**
	 * DAO instance
	 */
	private VideoCommentDAO dao = new VideoCommentDAO();
	
	private VideoDAO videoDao = new VideoDAO();

	/**
	 * Get Count.
	 */
	@Override
	public int getTotalCount() {
		return dao.getTotalCount();
	}

	/**
	 * Get all list.
	 */
	@Override
	public List<VideoComment> getAllVideoComments() {
		return dao.getAllVideoComments();
	}
	
	public void loadVideoCommentsByPage(DataPageUtil<VideoComment> dataPageUtil) {
		dao.loadVideoCommentsByPage(dataPageUtil);
		
		UserCache userCache = CacheManager.getUserCache();
		List<VideoComment> rs = dataPageUtil.getResult();
		if(rs != null && rs.size() > 0) {
			for(VideoComment vc: rs) {
				Video video = videoDao.getVideo(vc.getVideoUid());
				if(video != null) {
					vc.setVideoName(video.getName());
				}
				User user = userCache.getUser(vc.getUserUid());
				if(user != null) {
					vc.setUserName(user.getLoginName());
				}
			}
		}
	}

	/**
	 * Get all list by pagination.
	 */
	@Override
	public List<VideoComment> getVideoComments(int start, int end) {
		return dao.getVideoComments(start, end);
	}

	/**
	 * Get VideoComment by primary key.
	 */
	@Override
	public VideoComment getVideoComment(String uid) {
		VideoComment v = dao.getVideoComment(uid);
		return v;
	}

	@Override
	public int getCommentsCountByVideo(String videoUid) {
		return dao.getCommentsCountByVideo(videoUid);
	}

	@Override
	public List<VideoComment> getCommentsByVideo(String videoUid, int start, int end) {
		return dao.getCommentsByVideo(videoUid, start, end);
	}

	@Override
	public int getGoodVoteCntByVideo(String videoUid) {
		return dao.getGoodVoteCntByVideo(videoUid);
	}

	@Override
	public int getBadVoteCntByVideo(String videoUid) {
		return dao.getBadVoteCntByVideo(videoUid);
	}

}